import Vue from 'vue'
import App from './App'
import store from './store'
import RoomClient from './RoomClient'
import './style/index.scss'
import config from './config'
import urlParse from 'url-parse'
import deviceInfo from './deviceInfo'
import postMessage from "./postMessage";
const start = async function () {
  const parse = new urlParse(window.location.href, true)
  const query = parse.query
  const useType = query.useType || '1'
  const peerId = query.peerId
  const roomId = query.roomId
  const callType = query.type
  const homeowner = query.homeowner
  await store.dispatch('setCallType', callType)
  await store.dispatch('setUseType', useType)
  await store.dispatch('setMePeerId', peerId)
  await store.dispatch('setRoomId', roomId)
  await store.dispatch('setHomeowner', homeowner)
  let params = {
    protooUrl: config.protooUrl,
    peerId: peerId,
    roomId: roomId,
    displayName: null,
    handler: query.handler || 'handleer',
    useSimulcast: true,
    useSharingSimulcast: true,
    forceTcp: false,
    produce: query.produce !== 'false',
    consume: query.consume !== 'false',
    forceH264: query.forceH264 === 'true',
    forceVP9: query.forceVP9 === 'true',
    svc: '',
    datachannel: true,
    info: false,
    faceDetection: false,
    externalVideo: false,
    throttleSecret: '',
    device: deviceInfo()
  }
  const room = new RoomClient(params)
  store.dispatch('createRoomClient', room).then(() => {})
  await room.join()
}
 new Vue({
   render: h => h(App),
   el: '#app',
   store
 })
postMessage(start)
